package com.zhenmaitang.clinic_sys.entity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import io.swagger.v3.oas.annotations.media.Schema;

/**
 * 用户实体类 - 系统用户信息
 */
@Schema(description = "系统用户实体", example = "用户信息")

public class User {
    @Schema(description = "用户ID", example = "1")
    private Integer id;
    
    @Schema(description = "用户名", example = "zhangsan", requiredMode = Schema.RequiredMode.REQUIRED)
    private String username;
    
    @Schema(description = "密码", example = "******", requiredMode = Schema.RequiredMode.REQUIRED)
    private String password;
    
    @Schema(description = "邮箱地址", example = "zhangsan@hospital.com")
    private String email;
    
    @Schema(description = "真实姓名", example = "张三", requiredMode = Schema.RequiredMode.REQUIRED)
    private String fullName;
    
    @Schema(description = "用户角色列表（从user_roles关联表获取）", example = "[DOCTOR, NURSE]", allowableValues = {"ADMIN", "DOCTOR", "NURSE", "PATIENT"})
    private List<String> role;
    
    @Schema(description = "所属部门ID", example = "1")
    private Integer departmentId;
    
    @Schema(description = "是否启用", example = "true", defaultValue = "true")
    private Boolean enabled;
    
    @Schema(description = "创建时间", example = "2024-01-15 10:30:00")
    private LocalDateTime createTime;
    
    @Schema(description = "更新时间", example = "2024-01-15 14:20:00")
    private LocalDateTime updateTime;

    // 构造函数
    public User() {}

    public User(String username, String password, String email, String fullName, List<String> role, Integer departmentId) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.fullName = fullName;
        this.role = role;
        this.departmentId = departmentId;
        this.enabled = true;
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
    }

    // Getter和Setter方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public List<String> getRole() {
        return role;
    }

    public void setRole(List<String> role) {
        this.role = role;
    }
    
    // 添加单个角色
    public void addRole(String role) {
        if (this.role == null) {
            this.role = new ArrayList<>();
        }
        if (!this.role.contains(role)) {
            this.role.add(role);
        }
    }
    
    // 移除角色
    public void removeRole(String role) {
        if (this.role != null) {
            this.role.remove(role);
        }
    }

    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", email='" + email + '\'' +
                ", fullName='" + fullName + '\'' +
                ", role='" + role + '\'' +
                ", departmentId=" + departmentId +
                ", enabled=" + enabled +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}